home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: theoder@aol.com (The Oder)
- Newsgroups: comp.lang.c
- Subject: A real basic problem?: (code!) long integers or compiler problem?
- Date: 18 Apr 1996 16:39:26 -0400
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4l699u$cgo@newsbf02.news.aol.com>
- References: <4l3mom$f26@newsbf02.news.aol.com>
- Reply-To: theoder@aol.com (The Oder)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- Repost of original problem: (code to follow)
-
- I'm in the process of relearning C and have been doing some beginning
- programs on my PC. I have two compilers (Borland C++ and Power C). My
- problem is that when I run a program using "long" integers (i.e. declare a
- variable as "long"), it locks up immediately and I have to reboot. This
- has happened with both compilers and with two different really basic
- programs (i.e. just trying to do a loop that will compute the first 10
- powers of 2, and another one that simply just tries to find the largest
- positive long value on my computer--> I can find the largest positive int
- value, but when I convert it to long, it locks up)
-
- Is this a problem I have with BOTH (?!?!) compilers, is it my computer
- (486-DX2, 8 megs RAM) or settings, or is it just something I haven't
- learned yet about long integers? One of these programs I copied directly
- from one of TWO books I'm using and it just locks up!
-
-
- Here's the code: (for the program that will return the largest positive
- long value on my machine)
-
- #include <stdio.h>
- #include "local.h"
-
- void main()
- {
- long i;
- long maxlng();
-
- i=maxlng();
- printf("max i= %d, max i+1= %d",i,i+1);
- }
-
- long maxlng()
- {
-
- long first, b;
-
- first= 10000;
- while (first >= 0)
- {
- b= first;
- printf("b= %d, first= %d\n",b, first);
- first++;
- }
- return (b);
- }
-
-
- Whether I change the %d to %ld, does not make any difference. If I put
- some printf statements in my loop, "first" is negative (!) sometimes
- during this loop even though the "while" statement is only supposed to
- work if "first" is positive!
-
- Thanks once again!
-
-